package com.demon.framework.common.exception;

import com.demon.framework.common.retcode.BaseRetCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * 业务异常
 *
 * @author Demon-HY
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BizException extends RuntimeException implements Serializable {

    private static final long serialVersionUID = -1L;

    public String code;
    public String errMsg;

    public BizException(BaseRetCode.RetCode retCode) {

        super(retCode.code + "\t" + retCode.message);
        this.code = retCode.code;
        this.errMsg = retCode.message;
    }

    public BizException(BaseRetCode.RetCode retCode, Throwable cause) {
        super(retCode.message, cause);
        this.code = retCode.code;
        this.errMsg = retCode.message;
    }

    public BizException(String errMsg) {
        super(errMsg);
        this.code = BaseRetCode.ERR_SERVER_EXCEPTION.code;
        this.errMsg = errMsg;
    }

    public BizException(String errMsg, Throwable cause) {
        super(errMsg, cause);
        this.code = BaseRetCode.ERR_SERVER_EXCEPTION.code;
        this.errMsg = errMsg;
    }
}
